import React, { useEffect, useState } from 'react'

export default function DemoCount() {
    const [count,setCount] = useState(0)
    const handleClick = () => {
        count > 0 && setCount(pre => pre -1 )
    }
    // useEffect钩子函数
    useEffect(() => {
        console.log(`我被点击了${count}次`);
    })
  return (
    <div>
        <h1>{count}</h1>
        <button onClick={handleClick}>-</button>
        <button onClick={()=>setCount(pre => pre +1 )}>+</button>
    </div>
  )
}
